package com.k2.gulimall.product.web;

import com.k2.gulimall.product.entity.CategoryEntity;
import com.k2.gulimall.product.service.CategoryService;
import com.k2.gulimall.product.vo.CateLog2Vo;
import org.redisson.Redisson;
import org.redisson.api.RCountDownLatch;
import org.redisson.api.RLock;
import org.redisson.api.RReadWriteLock;
import org.redisson.api.RSemaphore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import static com.k2.common.constant.AuthServerConstant.LOGIN_USER;

@Controller
public class IndexController {

    @Autowired
    CategoryService CategoryService;

//    @Autowired
//    Redisson Redisson;

    @Autowired
    StringRedisTemplate StringRedisTemplate;

    @GetMapping({"/", "index.html"})
    public String indexPage(Model model) {
        List<CategoryEntity> CategoryEntity = CategoryService.getLevel1Categorys();
        System.out.println(CategoryEntity);
        model.addAttribute("categorys", CategoryEntity);
        return "index";
    }

    //index/catalog.json
    @GetMapping("/index/catalog.json")
    @ResponseBody
    public Map<String, List<CateLog2Vo>> getCatalogJson() {
        Map<String, List<CateLog2Vo>> catalogJson = CategoryService.getCatalogJson();
        System.out.println(catalogJson);
        return catalogJson;
    }

}
